"""
File: web.py
Author: ershixiong
Date: 2024/3/22
describe:

"""
from selenium import webdriver


class Web:
    def __init__(self):
        self.driver = webdriver.Chrome()

    def get(self, url):
        self.driver.get(url)

    def click(self, locator: list):
        by = locator[0]
        value = locator[1]
        self.driver.find_element(by, value).click()

    def send_keys(self, params: list):
        by = params[0]
        value = params[1]
        content = params[2]

        self.driver.find_element(by, value).send_keys(content)

    def close(self):
        self.driver.close()

    def run_step(self, step):
        for key, value in step.items():
            if key == '打开':
                ...
            elif key == '访问':
                self.get(value)
            elif key == '点击':
                self.click(value)
            elif key == '输入':
                self.send_keys(value)
            elif key == '断言':
                assert eval(value)
            elif key == '关闭':
                self.close()


web: Web = None
